package com.bbzn.device.client.controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.facebody.model.v20191230.GetFaceEntityResponse;
import com.aliyuncs.facebody.model.v20191230.ListFaceEntitiesResponse;
import com.aliyuncs.facebody.model.v20191230.SearchFaceResponse;
import com.bbzn.device.client.vo.req.FaceDbVO;
import com.bbzn.device.client.vo.req.FaceEntityVO;
import com.bbzn.device.client.vo.req.FaceVO;
import com.bbzn.device.client.aspect.OperationAnnotation;
import com.bbzn.device.client.constant.CrudConstant;
import com.bbzn.device.client.constant.FaceConstant;
import com.bbzn.device.client.constant.OssConstant;
import com.bbzn.device.client.dataobject.Face;
import com.bbzn.device.client.dataobject.FaceDb;
import com.bbzn.device.client.dataobject.SystemParam;
import com.bbzn.device.client.dto.face.FaceDTO;
import com.bbzn.device.client.exception.DefinitException;
import com.bbzn.device.client.service.CommonService;
import com.bbzn.device.client.service.FaceDbService;
import com.bbzn.device.client.service.FaceService;
import com.bbzn.device.client.service.SystemParamByCacheService;
import com.bbzn.device.client.utils.BaseApiService;
import com.bbzn.device.client.utils.BaseResponse;
import com.bbzn.device.client.utils.MayiktJwtUtils;
import com.bbzn.device.client.utils.OptionalBean;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author: jianghongyuan
 * @Date : 2022/01/17 09:00
 * @Version 1.0
 */


@Api(value = "Face", tags = "人脸")
//@CrossOrigin
@RestController
@RequestMapping("/face")
public class FaceController extends BaseApiService {

    private static Logger logger = LoggerFactory.getLogger(FaceController.class);

    @Autowired
    private CommonService commonService;

    @Autowired
    private SystemParamByCacheService systemParamByCacheService;

    @Autowired
    private FaceService faceService;

    @Autowired
    private FaceDbService faceDbService;


    /**
     * 查看人脸库列表
     *
     * @return
     */
    @OperationAnnotation(content = "查看人脸库列表")
    @RequestMapping(value = "/getListFaceDbs", method = RequestMethod.POST)
    public BaseResponse getListFaceDbs(HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        Long userId = commonService.getUserId(request);
        int roleId = MayiktJwtUtils.getRoleId(request, secretKey);
        List<FaceDb> faceDbList = new ArrayList<>();
        FaceDb faceDb = new FaceDb();
        if (roleId == 1){
            //超级管理员
            faceDbList = faceDbService.findByAll(faceDb);
        }else {
            faceDb.setUserId(userId);
            faceDbList = faceDbService.findByAll(faceDb);
        }
        JSONObject data = new JSONObject();
        data.put("listFaceDbs", faceDbList);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.SELECT_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage(), data);
    }

    /**
     * 创建人脸库
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "创建人脸库")
    @RequestMapping(value = "/addFaceDb", method = RequestMethod.POST)
    public BaseResponse addFaceDb(@RequestBody FaceDbVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        Long userId = commonService.getUserId(request);
        if (!OptionalBean.ofNullable(reqVO.getName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.addFaceDb(userId,reqVO.getName(),language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     * 删除人脸库
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "删除人脸库")
    @RequestMapping(value = "/deleteFaceDb", method = RequestMethod.POST)
    public BaseResponse deleteFaceDb(@RequestBody FaceDbVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.deleteFaceDb(reqVO.getName(), language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.DELETE_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     * 查询人脸样本列表
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "查询人脸样本列表")
    @RequestMapping(value = "/getListFaceEntities", method = RequestMethod.POST)
    public BaseResponse getListFaceEntities(@RequestBody FaceEntityVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        ListFaceEntitiesResponse faceEntitiesResponse = faceService.getListFaceEntities(reqVO, language);
        JSONObject data = new JSONObject();
        data.put("listFaceEntities", faceEntitiesResponse.getData());
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.SELECT_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage(),data);
    }

    /**
     * 查询人脸样本
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "查询人脸样本")
    @RequestMapping(value = "/getFaceEntity", method = RequestMethod.POST)
    public BaseResponse getFaceEntity(@RequestBody FaceEntityVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        GetFaceEntityResponse faceEntityResponse = faceService.getFaceEntity(reqVO, language);
        JSONObject data = new JSONObject();
        data.put("getFaceEntity", faceEntityResponse.getData());
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.SELECT_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage(),data);
    }

    /**
     * 创建人脸样本
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "创建人脸样本")
    @RequestMapping(value = "/addFaceEntity", method = RequestMethod.POST)
    public BaseResponse addFaceEntity(@RequestBody FaceEntityVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        Long userId = commonService.getUserId(request);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.addFaceEntity(reqVO, language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     * 更新人脸样本
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "更新人脸样本")
    @RequestMapping(value = "/updateFaceEntity", method = RequestMethod.POST)
    public BaseResponse updateFaceEntity(@RequestBody FaceEntityVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.updateFaceEntity(reqVO,language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.MODIFY_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     * 删除人脸样本
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "删除人脸样本")
    @RequestMapping(value = "/deleteFaceEntity", method = RequestMethod.POST)
    public BaseResponse deleteFaceEntity(@RequestBody FaceEntityVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.deleteFaceEntity(reqVO,language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.DELETE_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     *  查询人脸数据列表
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = " 查询人脸数据列表")
    @RequestMapping(value = "/getFaceList", method = RequestMethod.POST)
    public BaseResponse getFaceList(@RequestBody FaceVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        Face face = new Face();
        face.setDbName(reqVO.getDbName());
        face.setUserId(Long.valueOf(reqVO.getEntityId()));
        List<FaceDTO> faceList = faceService.findAllJoinUser(face);
        JSONObject data = new JSONObject();
        data.put("getFaceList", faceList);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage(),data);
    }

    /**
     *  添加人脸数据
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = " 添加人脸数据")
    @RequestMapping(value = "/addFaceTest", method = RequestMethod.POST)
    public BaseResponse addFaceTest(@RequestBody FaceVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        String userName = MayiktJwtUtils.getUsername(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getImageUrl()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_IMAGEURL_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.addFace(reqVO, userName, language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     *  添加人脸数据
     *
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = " 添加人脸数据")
    @RequestMapping(value = "/addFace", method = RequestMethod.POST)
    public BaseResponse addFace(MultipartFile file, @RequestParam String dbName, @RequestParam String entityId, @RequestParam String extraData,
                                @RequestParam Float qualityScoreThreshold,
                                @RequestParam Float similarityScoreThresholdInEntity,
                                @RequestParam Float similarityScoreThresholdBetweenEntity,
                                HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        String userName = MayiktJwtUtils.getUsername(request, secretKey);
        if (!OptionalBean.ofNullable(dbName).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(entityId).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        /*if (!OptionalBean.ofNullable(reqVO.getImageUrl()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_IMAGEURL_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }

        faceService.addFace(reqVO, userName, language);*/

        if (Objects.isNull(file)) {
            SystemParam systemParam = systemParamByCacheService.getValues(OssConstant.OSS_ENUM, OssConstant.OSS_NU_ERROR_PREFIX + language);
            return setResultError(systemParam.getCode(), systemParam.getMassage());
        }
        //头像文件大小不超过10MB
        if (file.getSize() > 10 * 1024 * 1024) {
            SystemParam systemParam = systemParamByCacheService.getValues(OssConstant.OSS_ENUM, OssConstant.OSS_SIZE_10MB_PREFIX + language);
            return setResultError(systemParam.getCode(), systemParam.getMassage());
        }
        String imgUrl = faceService.uploadFaceImg(file);
        if (Objects.isNull(imgUrl)) {
            SystemParam systemParam = systemParamByCacheService.getValues(OssConstant.OSS_ENUM, OssConstant.OSS_FAILED_PREFIX + language);
            return setResultError(systemParam.getCode(), systemParam.getMassage());
        }
        FaceVO reqVO = new FaceVO();
        reqVO.setDbName(dbName);
        reqVO.setEntityId(entityId);
        reqVO.setImageUrl(imgUrl);
        reqVO.setExtraData(extraData);
        reqVO.setQualityScoreThreshold(qualityScoreThreshold);
        reqVO.setSimilarityScoreThresholdInEntity(similarityScoreThresholdInEntity);
        reqVO.setSimilarityScoreThresholdBetweenEntity(similarityScoreThresholdBetweenEntity);
        faceService.addFace(reqVO, userName, language);

        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     *  批量添加人脸数据
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = " 批量添加人脸数据")
    @RequestMapping(value = "/batchAddFaces", method = RequestMethod.POST)
    public BaseResponse batchAddFaces(@RequestBody FaceVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        String userName = MayiktJwtUtils.getUsername(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getImageUrl()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_IMAGEURL_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getEntityId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.batchAddFaces(reqVO, language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.ADD_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

    /**
     *  搜索人脸
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = " 搜索人脸")
    @RequestMapping(value = "/searchFace", method = RequestMethod.POST)
    public BaseResponse searchFace(@RequestBody FaceVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbNames()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (reqVO.getDbNames().contains("，")){
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getImageUrl()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_IMAGEURL_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getLimit()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_LIMIT_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        SearchFaceResponse faceResponse = faceService.searchFace(reqVO, language);
        JSONObject data = new JSONObject();
        data.put("searchFace", faceResponse.getData());
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.SELECT_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage(),data);
    }

    /**
     * 删除人脸样本
     *
     * @param reqVO
     * @param request
     * @return
     * @throws Exception
     */
    @OperationAnnotation(content = "删除人脸")
    @RequestMapping(value = "/deleteFace", method = RequestMethod.POST)
    public BaseResponse deleteFace(@RequestBody FaceVO reqVO, HttpServletRequest request) throws Exception {
        String secretKey = commonService.getWebSalt(request);
        String language = MayiktJwtUtils.getLanguage(request, secretKey);
        if (!OptionalBean.ofNullable(reqVO.getDbName()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_FACEDBNAME_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        if (!OptionalBean.ofNullable(reqVO.getFaceId()).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(FaceConstant.FACE_ENUM, FaceConstant.FACE_NO_ENTITYID_ERROR_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        faceService.deleteFace(reqVO,language);
        SystemParam systemParam = systemParamByCacheService.getValues(CrudConstant.CRUD_ENUM, CrudConstant.DELETE_SUCCESS_PREFIX + language);
        return setResultSuccess(systemParam.getMassage());
    }

}
